Audio
Data Blocks
The waveInAddBuffer
Before using
one of these functions to pass a data block to a device driver, you must
allocate memory for the data block and the header structure that describes the
data block. The headers can be prepared and unprepared by using the following
functions.
Function |
Description |
waveInPrepareHeader |
Prepares a
waveform-audio input data block. |
waveInUnprepareHeader |
Cleans up
the preparation on a waveform-audio input data block. |
waveOutPrepareHeader |
Prepares a
waveform-audio output data block. |
waveOutUnprepareHeader |
Cleans up
the preparation on a waveform-audio output data block. |
Before you
pass an audio data block to a device driver, you must prepare the data block by
passing it to either waveInPrepareHeader
Unless the
waveform-audio input and output data is small enough to be contained in a
single data block, applications must continually supply the device driver with
data blocks until playback or recording is complete.
Even if a
single data block is used, an application must be able to determine when a
device driver is finished with the data block so the application can free the
memory associated with the data block and header structure. There are several
ways to determine when a device driver is finished with a data block:
By specifying a callback
function to receive a message sent by the driver when it is finished with a
data block
By using an event callback
By specifying a window or
thread to receive a message sent by the driver when it is finished with a data
block
By polling the WHDR_DONE bit in
the dwFlags member of the WAVEHDR structure sent with each data block
If an
application does not get a data block to the device driver when needed, there can
be an audible gap in playback or a loss of incoming recorded information. This
requires at least a double-buffering scheme staying at least one data block ahead of the device driver.
The following
sections describe ways to determine when a device driver is finished with a
data block:
Using a callback function to
process driver messages
Using an event callback to
process driver messages
Using a window or thread to
process driver messages
Managing data blocks by
polling